package testHarness;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Iterator;

import functions.PaymentData;
import functions.SinglePayment;

public class Main {
	public final static String fileName = "PaymentData.txt";
	/**
	 * @param args
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 * @throws ClassNotFoundException 
	 */
	public static void main_old(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
		// TODO Auto-generated method stub
		PaymentData pd = new PaymentData();
		for(int i = 0; i < 10; i++){
			pd.addPayment(i, 1, 2011, 2.34*i);
		}
		print(pd.getArray());
		System.out.println("");
//		pd.removePayment(3);
//		pd.removePayment(3);
		pd.insertPayment(12, 1, 1111, 123.45, 3);
		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(fileName));
		out.writeObject(pd);
		out.close();
		print(pd.getArray());
		ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName));
		PaymentData pdr = (PaymentData) in.readObject();
		in.close();
		ArrayList<SinglePayment> al = pdr.getArray();
//		al.remove(3);
//		al.remove(3);
		System.out.println("");
		print(al);
	}
	
	public static void print(ArrayList<SinglePayment> al){
		Iterator<SinglePayment> it = al.iterator();
		int count = 0;
		while(it.hasNext()){
			System.out.println(count + " " + it.next().toFormattedString());
			count++;
		}
	}
}
